function pokemon(id, level, strength, speed, hpmax, exp, expToNextLevel, money, items, history) {
	this.id = id;
	this.level = level;
	this.strength = strength;
	this.speed = speed;
	this.hpmax = hpmax;
	this.exp = exp;
	this.expToNextLevel = expToNextLevel;
	this.money = money;
	this.items = items;
	this.history = history;
}

function generateRandomPokemon(myPokemon) {
	var rand_id = Math.floor(Math.random()*4);
	var rand_level = Math.max(parseInt(myPokemon.level)+Math.floor(Math.random()*11)-5,1);
	var rand_strength = 0;
	var rand_hpmax = 0;
	var rand_speed = 0;
	for(i = 0; i < rand_level; ++i) {
		rand_strength = rand_strength + Math.random()+2;
		rand_speed = rand_speed + Math.random()+2;
		rand_hpmax = rand_hpmax + Math.random()*3+8;
	}
	rand_strength = Math.floor(rand_strength);
	rand_hpmax = Math.floor(rand_hpmax);
	rand_speed = Math.floor(rand_speed);
	var rand_exp = Math.floor(Math.random()*21+90)*rand_level;
	var rand_money = Math.floor(Math.random()*21+90)*rand_level;
	var randomPokemon = new pokemon(rand_id, rand_level, rand_strength, rand_speed,
									rand_hpmax, rand_exp, 0, rand_money, undefined, undefined);
	return randomPokemon;
}

function generateUserPokemon(level, id) {
	var pt_strength = 0;
	var pt_hpmax = 0;
	var pt_speed = 0;
	for(i = 0; i < level; ++i) {
		pt_strength = pt_strength + Math.random()+3;
		pt_speed = pt_speed + Math.random()+3;
		pt_hpmax = pt_hpmax + Math.random()*3+10;
	}
	pt_strength = Math.floor(pt_strength);
	pt_hpmax = Math.floor(pt_hpmax);
	pt_speed = Math.floor(pt_speed);
	var pt_exp = 0;
	for(i = 1; i < level; ++i) {
		pt_exp = pt_exp + getExpToNextLevel(i);
	}
	var pt_money = 0;
	var pt_items = undefined;
	var pt_history = undefined;
	var pt_expToNextLevel = getExpToNextLevel(level);
	var userPokemon = new pokemon(id, level, pt_strength, pt_speed, pt_hpmax, pt_exp,
								  pt_expToNextLevel, pt_money, pt_items, pt_history);
	return userPokemon;
}

function levelUp(pokemon, exp) {
	pokemon.level = parseInt(pokemon.level) + 1;
	pokemon.expToNextLevel = getExpToNextLevel(pokemon.level)-exp;
	pokemon.strength = Math.floor(parseInt(pokemon.strength) + Math.random()+3);
	pokemon.speed = Math.floor(parseInt(pokemon.speed) + Math.random()+3);
	pokemon.hpmax = Math.floor(parseInt(pokemon.hpmax) + Math.random()*3+10);
	return pokemon;
}
function battle(pokemon1, pokemon2) {
	var pokemon1Hp = parseInt(pokemon1.hpmax);
	var pokemon2Hp = parseInt(pokemon2.hpmax);
	while(true) {
		pokemon2Hp = pokemon2Hp - parseInt(pokemon1.strength)*(Math.random()+0.5);
		pokemon1Hp = pokemon1Hp - parseInt(pokemon2.strength)*(Math.random()+0.5);
		if(pokemon1.speed > pokemon2.speed) {
			if(pokemon2Hp<=0) return true;
			if(pokemon1Hp<=0) return false;
		} else {
			if(pokemon1Hp<=0) return false;
			if(pokemon2Hp<=0) return true;
		}
		console.log("1: "+pokemon1Hp+" 2: "+pokemon2Hp);
	}
}

function getExpToNextLevel(level) {
	return (5*Math.pow(level,3)/4)*20;
}